package com.tarena.lbs.user.rpc;

import com.tarena.lbs.user.api.UserApi;
import com.tarena.lbs.user.api.pojo.dto.AdminDto;
import com.tarena.lbs.user.dao.mapper.AdminMapper;
import com.tarena.lbs.user.dao.mapper.UserGroupMapper;
import com.tarena.lbs.user.dao.mapper.UserMapper;
import com.tarena.lbs.user.dao.mapper.UserTagsMapper;
import com.tarena.lbs.user.service.impl.AdminServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Collections;
import java.util.List;


@Slf4j
@DubboService
public  class UserApiImpl implements UserApi {

    @Autowired
    private AdminServiceImpl adminService;
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserGroupMapper userGroupMapper;
    @Autowired
    private UserTagsMapper userTagsMapper;

    @Override
    public List<Integer> getUserGroupIds(Integer userId, Integer businessId) {
        int tagId=userTagsMapper.selectByUserId(userId);
        List<Integer> userGroupIds=userGroupMapper.selectByTag(tagId);
        return userGroupIds;
    }

    @Override
    public AdminDto getAdminById(Integer adminId) {
        return adminService.detail(adminId);
    }

    @Override
    public Integer getBusinessId(Integer userId) {
        try{
            int tagId=userTagsMapper.selectByUserId(userId);
            Integer businessId=userGroupMapper.selectBusinessId(tagId);
            return businessId;
        }catch (Exception e){
            log.error("没获取到用户标签，可能是在小刀测试:{}",e);
        }
        return null;
    }
}
